import { Toast } from 'vant'
import {createWebHashHistory,createWebHistory,createRouter} from 'vue-router'

const  router    =  createRouter({
      history:createWebHashHistory(),
      routes:[
        {
            path:'/',
            component:()=> import('../views/myHome/MyHome')
        },
        {
            path:'/home',
            component:()=> import('../views/myHome/MyHome')
        },
        {
            path:'/cart',
            component:()=> import('../views/myCart/MyCart.vue'),
            meta:{
                isAuth:true
             }
        },
        {
            path:'/order',
            component:()=> import('../views/myOrder/MyOrder.vue'),
            meta:{
                isAuth:true
             }
        },
        {
            path:'/mine',
            component:()=> import('../views/mine/Mine.vue'),
            meta:{
                isAuth:true
             }
        },
        {
              path:'/store',
              component:()=>import('../views/myStore/MyStore')
        },
        {
            path:'/createorder',
            component:()=>import('../views/createOrder/CreateOrder.vue'),
            meta:{
                isAuth:true
             }
      },
      {
        path:'/address',
        component:()=>import('../views/Address/Address.vue'),
        meta:{
            isAuth:true
         }
  },

  {
     path:'/addressedit',

     component:()=>import('../views/AdressEdit/AddressEdit.vue'),
     meta:{
        isAuth:true
     }
  },

  {
    path:'/login',

    component:()=>import('../views/Login/Login')
 },
 {
    path:'/register',

    component:()=>import('../views/Register/Register')
 },
 {
    path:'/userinfoedit',

    component:()=>import('../views/UserInfoEdit/UserInfoEdit')
 }


      ]

})



 router.beforeEach((to,from,next)=>{

    if(to.meta.isAuth){
         if(localStorage.isLogin){
            next()
         }else{

            Toast('请先登录')  
            router.push('/login')
        }         

    } else{

        next()
    }

 })





export  default router